package com.example.click;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    TextView tvInfo, tvInfoOne;
    Button btnThree, btnFour, btnFive;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        tvInfo = findViewById(R.id.tv_info);
        tvInfoOne = findViewById(R.id.tv_info_1);
        Button btnTwo = findViewById(R.id.btn_2);
        btnThree =findViewById(R.id.btn_3);
        btnFour =findViewById(R.id.btn_4);
        btnFive =findViewById(R.id.btn_5);

        btnThree.setOnClickListener(this);
        btnFour.setOnClickListener(this);
        btnFive.setOnClickListener(this);

        btnTwo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tvInfo.setText("按钮2被点击！");
            }
        });

    }

    public void buttonOneClicked(View view){

        tvInfo.setText("按钮1被点击！");
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.btn_3){
            tvInfoOne.setText("按钮3被点击！");
        }
        if (id == R.id.btn_4){
            tvInfoOne.setText("按钮4被点击！");
        }
        if (id == R.id.btn_5){
            tvInfoOne.setText("按钮5被点击！");
        }
    }
}